#include <iostream>
#include <algorithm>

using namespace std;

const int T = 1010;

int N, V;
int v[T], w[T];
int dp[T][T];

int main()
{
    cin >> N >> V;
    for (int i = 1; i <= N; i++)
        cin >> v[i] >> w[i];

    for (int i = 1; i <= N; i++)
        for (int j = 0; j <= V; j++)
        {
            dp[i][j] = dp[i - 1][j];
            if (j - v[i] >= 0)
                dp[i][j] = max(dp[i][j], dp[i][j - v[i]] + w[i]);
        }
    cout << dp[N][V];

    return 0;
}
